/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tetris_invader.windows;

import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
import tetris_invader.personagens.Fabrica;

/**
 * Painel Game Over.<br>
 * É chamado quando se perde o jogo, mesmo.
 */
public class GameOver extends JPanel {

    private JButton restart;
    private JButton mainMenu;
    private JButton exit;
    private JPanel painel;
    private JTextField name;
    private JButton save;
    private int score;
    private Image image[];

    public GameOver() {
        restart = new JButton("Restart");
        mainMenu = new JButton("Main Menu");
        exit = new JButton("Exit");
        painel = new JPanel();
        name = new JTextField("Your Name Here", 30);
        save = new JButton("Save Record");
        score = 0;

        this.setLayout(new FlowLayout(FlowLayout.LEADING));

        painel.add(restart);
        painel.add(mainMenu);
        painel.add(exit);

        this.add(name);
        this.add(save);
        this.add(painel);

        image = new Image[1];
        String filename = "/images/gameOver.png";
        URL url = Fabrica.class.getResource(filename);
        image[0] = Toolkit.getDefaultToolkit().getImage(url);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        Graphics2D g2 = (Graphics2D) g;

        g2.drawImage(image[0], 0, 0, this);

        Font f = new Font(null, Font.BOLD, 60);

        g2.setFont(f);
        g2.drawString("Game Over!!", 120, 180);
        g2.drawString("Your Score: " + score, 120, 250);
    }


    /**
     * funcao que apenas pega a quantidade de pontos qu eo jogador conseguiu
     * @param points quantidade de pontos adquirida
     */
    public void gameOver(int points) {
        this.score = points;
    }

    public void addListener(ActionListener e) {
        mainMenu.addActionListener(e);
        exit.addActionListener(e);
        save.addActionListener(e);
        restart.addActionListener(e);
    }
}
